/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package chelydra.sharelydra.server.web;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import chelydra.sharelydra.server.ejb.SLSManager;

/**
 *
 * @author scallion
 */
public class SLSLocator {

	private static Context ctx;
	private static SLSLocator instance = new SLSLocator();

	private SLSLocator() {
		try {
			ctx = new InitialContext();
		} catch (NamingException e) {
		}
	}

	public static SLSLocator getLocator() {
		return instance;
	}

	private <T> T getEjb(Class<T> ejbClass, String name) {
		try {
			T service = (T) ctx.lookup("ShareLydraServer/" + name+ "/local");
			return service;
		} catch (NamingException e) {
			return null;
		}
	}

	public SLSManager getManager() {
		return getEjb(SLSManager.class, "SLSManagerBean");
	}
}
